package com.jikedaquan.game.jwt.controller;


import com.jikedaquan.game.jwt.entity.Relation;
import com.jikedaquan.game.jwt.entity.User;
import com.jikedaquan.game.jwt.service.RelationService;
import com.jikedaquan.game.jwt.service.UserService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 好友关系 前端控制器
 * </p>
 *
 * @author jiake
 * @since 2019-10-31
 */
@Controller
@RequestMapping("/relation")
public class RelationController {

    @Resource
    private RelationService relationService;

    @Resource
    private UserService userService;
    @GetMapping(path = {"","/","/index","/index.html"})
    public String friend(Model model){
        //获取当前登陆用户
        User user = new User();
        user.setId(1);
        List<Relation> relations = relationService.getAllRelation(user);
        model.addAttribute("relations",relations);
        return "relation/home";
    };

    @GetMapping(path = {"status","status.html"})
    public String status(Model model){
        //接收好友id  临时查1
        User user = userService.getUserById(1);

        return "relation/status";
    }

    @GetMapping(path = {"request","request.html"})
    public String request(Model model){
        //获取请求信息, 暂时先自建
        Relation relation = new Relation();
        relation.setUserId(1);
        relation.setFriendId(5);
        relation.setStatus(1);
        relation.setCreateTime(new Date());
        relation.setFriendLevel("66");
        boolean result = false;
        if (relation.getStatus() == 1){
            result = relationService.insertRelation(relation);

        }else{
            result = relationService.updateRelation(relation);
        }
        model.addAttribute("status",relation.getStatus());
        return "relation/add";
    }
}

